<?php
include_once 'MY/extra_sql.php';
function GetID($prefix) {
	//第一步:初始化种子
	//microtime(); 是个数组
	$seedstr =split(" ",microtime(),5);
	$seed =$seedstr[0]*10000;
	//第二步:使用种子初始化随机数发生器
	srand($seed);
	//第三步:生成指定范围内的随机数
	$random =rand(1000,10000);

	$filename = date("Ymd", time()).$random.$prefix;

	return $filename;
}
class StudentController extends Zend_Controller_Action{	
	function init(){       
		if($_SESSION['user']==""){
			echo "<script>window.location='../user/login';</script>"; exit;
		}
		$this->registry = Zend_Registry::getInstance();
		$this->view = $this->registry['view'];
		$this->view->baseUrl = $this->_request->getBaseUrl();
		$this->view->template = "student";
		$this->view->conf = new Zend_Config(require './application/configs/config.php');

		$group_id = $_SESSION['user']['group_id'];
		$group = new Group();
		$group = $group->getgroupByid($group_id);
		$groups = explode(',',$group[0]['models']);
		if(!in_array('student',$groups)){
			echo "<script>alert('No Permission To Enter!');history.go('-1');</script>";exit();
		}
	}

	public function indexAction(){
		$filter=new Zend_Filter_StripTags();
		
		//项目信息
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
			$arrProjectType[$key]['year'] = $arrYear[$key];
		}
		$cc = array();
	    foreach ($arrProjectType as $k=>$v){
	    	$j=0;
	    	for($i=0;$i<count($v);$i++){
	    	  $cc[$i]+=$v[$i];	
	    	}	    	
	    }
	    $cc['year'] = '小结';
        $arrProjectType[] = $cc;
		$this->view->arrProjectType = $arrProjectType;
		
		//学生信息
		$student = new Student();
		$studentverify = new StudentVerify();
		$students = $student->getAllStudents('', '', '');
		$this->view->total = count($students);
		$this->view->top = $student->getTopStudents();
		
		//学生标签
		$tag = new Tag();
		$studenttag = new StudentTag();
		$arrStudentTag = $studenttag->getStudentTag();
		$arrTag = array();
		if (!empty($arrStudentTag)) {
			foreach ($arrStudentTag as $row) {
				if (!array_key_exists($row['tag_id'], $arrTag)) {
					$arrTag[$row['tag_id']]['tag_id'] = $row['tag_id'];
					$arrTag[$row['tag_id']]['num'] = 1;
					$arrTagId[] = $row['tag_id'];
				}else{
					$arrTag[$row['tag_id']]['num']++;
				}
			}
			$tags = $tag->getAllTagInArray($arrTagId);
			foreach($tags as $row){
				$arrTag[$row['tag_id']]['tag_name'] = $row['name'];
			}
			$this->view->tags = $arrTag;
		}
		
		for($i=1;$i<=5;$i++){
			$studentsverifys = $studentverify->getstudent_verifyByverify_id($i);
			$stu = array('0'=>'0');
			for($j=0;$j<count($studentsverifys);$j++){
				$stu[].=$studentsverifys[$j]['student_id'];
			}
			$ver = "verify".$i;
			$this->view->$ver = $student->getAllstudentInArray($stu);
		}
		echo $this->view->render('student/index.html');
	}
	
	public function verifyAction(){
		$filter=new Zend_Filter_StripTags();
		$student_id=$filter->filter(($this->_request->getParam('student_id')));
		$studentverify = new StudentVerify();
		$student = new Student();
		$this->view->student = $student->getStudentBystudent_id($student_id);
		$this->view->verify = $studentverify->getverifybystudentid($student_id);
		echo $this->view->render('student/verify.html');
	}
	
	public function verifydelAction(){
		$filter=new Zend_Filter_StripTags();
		$studentverify = new StudentVerify();
		$student_id=$filter->filter(($this->_request->getParam('student_id')));
		$verify_id=$filter->filter(($this->_request->getParam('verify_id')));
		$query = $studentverify->delstudent_verifyByid($student_id, $verify_id);
		if($query){
			echo "<script>window.location='verify?student_id=".$student_id."'</script>";
		}else{
			echo "<script>alert('Failure!');window.location='verify?student_id=".$student_id."'</script>";
		}
	}
        
	//学生获得资格证书
	public function verifyaddAction(){
		$filter=new Zend_Filter_StripTags();
		$studentverify = new StudentVerify();
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$student_id=$filter->filter(($this->_request->getPost('student_id')));
			$verify_id=$filter->filter(($this->_request->getPost('verify_id')));
			if(empty($student_id) || empty($verify_id)){
				echo "<script>alert('Failure!');window.location='verify?student_id=".$student_id."'</script>";
				return false;
			}
			$create_time = time();
			$data = array(
				'student_id'=>$student_id,
				'verify_id'=>$verify_id,
				'create_time'=>$create_time
			);
			$id = $studentverify->insert($data);
			if($id){
				echo "<script>window.location='verify?student_id=".$student_id."'</script>";
			}else{
				echo "<script>alert('Failure!');window.location='verify?student_id=".$student_id."'</script>";
			}
		}
	}

	//添加学生方法
	public function addAction(){
		$filter=new Zend_Filter_StripTags();
		$student = new Student();
		$studentclass = new StudentClass();
		$operation = new Operation();
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$name=$filter->filter(($this->_request->getPost('name')));
			$summary=$this->_request->getPost('summary');
			$pinyin=$filter->filter(($this->_request->getPost('pinyin')));
			$sex=$filter->filter(($this->_request->getPost('sex')));
			$company_id=$filter->filter(($this->_request->getPost('company_id')));
			$email=$filter->filter(($this->_request->getPost('email')));
			$telephone=$filter->filter(($this->_request->getPost('telephone')));
			$mobile=$filter->filter(($this->_request->getPost('mobile')));
			$duties=$filter->filter(($this->_request->getPost('duties')));
			$duties_now=$filter->filter(($this->_request->getPost('duties_now')));
			$post=$filter->filter(($this->_request->getPost('post')));
	        $user_id=$_SESSION['user']['user_id'];
			$time = strtotime(date("Y-m-d H:i:s"));
			$birthday = strtotime($birthday);
			$path= "public/files/student/".date("Ym",time())."/";//上传路径
			if (!file_exists($path)) {
				mkdir("$path", 0700);
			}//END IF
			$path= "public/files/student/".date("Ym",time())."/".date("d",time())."/";//上传路径
			if (!file_exists($path)) {
				mkdir("$path", 0700);
			}
			$file1=GetID( ".".strtolower(substr($_FILES['photo']['name'], (strrpos($_FILES['photo']['name'], '.') + 1))));
			$path = $path.$file1;
			move_uploaded_file($_FILES["photo"]["tmp_name"],$path);
			$data = array(
				'name'=>$name,
				'summary'=>$summary,
				'pinyin'=>$pinyin,
				'sex'=>$sex,
				'company_id'=>$company_id,
				'email'=>$email,
				'telephone'=>$telephone,
				'mobile'=>$mobile,
				'duties'=>$duties,
			    'duties_now'=>$duties_now,
				'post'=>$post,
				'photo'=>$path,
				'create_time'=>$time,
			    'user_id'=>$user_id
			);
			$student_message = $student->getStudentBystudent_name($name);
			
				$student_id = $student->insert($data);
				if ($student_id) {
					$time = time();
					$data = array(
						'op_name'=>'add',
						'model_name'=>'student',
						'user_id'=>$_SESSION['user']['user_id'],
						'user_name'=>$_SESSION['user']['user_name'],
						'name'=>'增加学生',
						'create_time'=>$time
					);
					$query = $operation->insert($data);
					echo "<script>window.location='detail?student_id=".$student_id."'</script>";
				}else{

				}
			
		}
		echo $this->view->render('student/add.html');
	}

	//修改学生方法
	public function editAction(){
		$filter=new Zend_Filter_StripTags();
		$student = new Student();
		$company = new Company();
		$studentclass = new StudentClass();
		$operation = new Operation();
		$class = new Classes();
		$student_id=$filter->filter(($this->_request->getParam('student_id')));
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$name=$filter->filter(($this->_request->getPost('name')));
			$summary=$this->_request->getPost('summary');
			$pinyin=$filter->filter(($this->_request->getPost('pinyin')));
			$sex=$filter->filter(($this->_request->getPost('sex')));
			$company_id=$filter->filter(($this->_request->getPost('company_id')));
			$email=$filter->filter(($this->_request->getPost('email')));
			$telephone=$filter->filter(($this->_request->getPost('telephone')));
			$mobile=$filter->filter(($this->_request->getPost('mobile')));
			$duties=$filter->filter(($this->_request->getPost('duties')));
			$duties_now=$filter->filter(($this->_request->getPost('duties_now')));
			$post=$filter->filter(($this->_request->getPost('post')));
            $current_photo=$filter->filter(($this->_request->getPost('current_photo')));
            $photo_del=$filter->filter(($this->_request->getPost('photo_del')));
		
			$time = strtotime(date("Y-m-d H:i:s"));
            if($_FILES['photo']['name']!=""){
				$path= "public/files/student/".date("Ym",time())."/";//上传路径
				if (!file_exists($path)) {
					mkdir("$path", 0700);
				}//END IF
				$path= "public/files/student/".date("Ym",time())."/".date("d",time())."/";//上传路径
				if (!file_exists($path)) {
					mkdir("$path", 0700);
				}
				$file1=GetID( ".".strtolower(substr($_FILES['photo']['name'], (strrpos($_FILES['photo']['name'], '.') + 1))));
				$path = $path.$file1;
				move_uploaded_file($_FILES["photo"]["tmp_name"],$path);
				} else {
					if($photo_del=="1"){
						$path = "";
					}else{
						$path = $current_photo;
					}					
				}
				$data = array(
					'name'=>$name,
					'summary'=>$summary,
					'pinyin'=>$pinyin,
					'sex'=>$sex,
					'company_id'=>$company_id,
					'email'=>$email,
					'telephone'=>$telephone,
					'mobile'=>$mobile,
					'duties'=>$duties,
				    'duties_now'=>$duties_now,
					'post'=>$post,
					'photo'=>$path,
					'create_time'=>$time
				);
			$student->updateStudentBySid($data, $student_id);
			$time = time();
			$data = array(
				'op_name'=>'edit',
				'model_name'=>'student',
				'user_id'=>$_SESSION['user']['user_id'],
				'user_name'=>$_SESSION['user']['user_name'],
				'name'=>'修改学生',
				'create_time'=>$time
			);
			$query = $operation->insert($data);
			echo "<script>window.location='detail?student_id=".$student_id."'</script>";
		}else{
			$this->view->student= $student->getStudentBystudent_id($student_id);
			$company = $company->getCompanyBycompany_id($this->view->student[0]['company_id']);
			if(count($company)=='0'){
				$this->view->company_name="";
			}else{
				$this->view->company_name = $company[0]['name'];
            }
		}
		echo $this->view->render('student/edit.html');
	}

	//学生列表页
	public function listAction(){
		$filter=new Zend_Filter_StripTags();
		$student = new Student();
        $operation = new Operation();
		$page=$filter->filter(($this->_request->getParam('page')));
		$search_name=$filter->filter(($this->_request->getParam('search_name')));
		if($page==""){
			$page="1";
		}
		$count = $student->getAllStudents('','',$search_name);
    	//总条数
        $total = count($count);
    	//总页数
		$perpage = "10";
		$pages = ceil($total/$perpage);
		$this->view->students = $student->getAllStudents($page,$perpage,$search_name);
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;
        $this->view->search_name = $search_name;
		$time = time();
		$data = array(
			'op_name'=>'list',
			'model_name'=>'student',
			'user_id'=>$_SESSION['user']['user_id'],
			'user_name'=>$_SESSION['user']['user_name'],
			'name'=>'取得所有学生',
			'create_time'=>$time
		);
		$query = $operation->insert($data);
		echo $this->view->render('student/list.html');
	}

	//学生详情页
	public function detailAction(){
		$filter=new Zend_Filter_StripTags();
		$student = new Student();
		$project = new Project();
		$class = new Classes();
		$course = new Course();
		$company = new Company();
        $operation = new Operation();
        $studentclass = new StudentClass();
		$studenttag = new StudentTag();
		$tag = new Tag();
		$db = new mysql(constant('dbhost'),constant('dbuser'),constant('dbpass'),constant('dbname'),"UTF8");
		$student_id=$filter->filter(($this->_request->getParam('student_id')));
		$page=$filter->filter(($this->_request->getParam('page')));
		//comment的页数
		if($page==""){
			$page="1";
		}
		$show_project = $project->getprojectBystudent_id($student_id);
		$this->view->projects = $show_project;
		$student_cat = 0;
		if (!empty($show_project) && is_array($show_project)) {
			foreach ($show_project as $row) {
				if ($row['category'] > $student_cat) {
					$student_cat = $row['category'];
				}
			}
		}
		$this->view->student = $student->getStudentBystudent_id($student_id);
		$this->view->student_cat = $student_cat;

		//查询所有的comment和发表comment的用户名
		$count = $db->select_comment('','',$student_id,'2');

		//总条数
		$total = count($count);

		//总页数
		$perpage = "2";
		$pages = ceil($total/$perpage);
		$start = ($page-1)*$perpage;
		$end = $perpage;
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;

		$this->view->comments = $db->select_comment($start,$end,$student_id,'2');
		//公司名字
		$company = $company->getCompanyBycompany_id($this->view->student[0]['company_id']);
		if(count($company)==''){
			$this->view->company_name="";
		}else{
			$this->view->company_name = $company[0]['name'];
		}
		//根据学生student_id 取出他所参加的所有班级id
		$classes = $studentclass->getstudent_classBystudent_id($student_id);
		//print_r($classes);
		//把取到的所有classid存进数组，然后再查询出所有班级
		$class_array=array('0'=>'0');
		for($i=0;$i<count($classes);$i++){
			$class_array[].=$classes[$i]['class_id'];
		}
		$class_value = $class->getAllClassInArray($class_array);
		//print_r($class_value);
		foreach ($class_value as $key=>$row) {
			$class_value[$key]['verify_id'] = $classes[$key]['verify_id'];
		}
		$this->view->classes = $class_value;
		$tag_current = $studenttag->getstudenttagBystudent_id($student_id);
		$arr = array('0'=>'0');
		for($i=0;$i<count($tag_current);$i++){
			$arr[].=$tag_current[$i]['tag_id'];
		}
                   
		$this->view->tag_current = $tag->getAllTagInArray($arr);

		$time = time();
		$data = array(
			'op_name'=>'list',
			'model_name'=>'student',
			'user_id'=>$_SESSION['user']['user_id'],
			'user_name'=>$_SESSION['user']['user_name'],
			'name'=>'取得所有学生',
			'create_time'=>$time
		);
		$query = $operation->insert($data);
		echo $this->view->render('student/detail.html');
   }

	//删除学生
	public function deleteAction(){
		$filter=new Zend_Filter_StripTags();
		$student = new Student();
		$studentclass = new StudentClass();
		$operation = new Operation();
		$student_id=$filter->filter(($this->_request->getParam('student_id')));
		$query = $student->delStudentBystudent_id($student_id);
	
		if($query){
			//删除student_class表格里面的所有次学生的班级记录
			$student = $studentclass->delstudent_classBystudent_id($student_id);
			if($student){
				$time = time();
				$data = array(
					'op_name'=>'delete',
					'model_name'=>'student',
					'user_id'=>$_SESSION['user']['user_id'],
					'user_name'=>$_SESSION['user']['user_name'],
					'name'=>'删除学生',
					'create_time'=>$time
				);
				$query = $operation->insert($data);
				echo "<script>window.location='list'</script>";
			}    
		}else{
			
		}
	}
	
	public function hoverAction(){
		$filter=new Zend_Filter_StripTags();
		$search_name=$filter->filter(($this->_request->getParam('search_name')));
		$student = new Student();
		$this->view->students = $student->getAllStudents('','',$search_name);
		echo $this->view->render('student/hover.html');
	}
	
	//删除标签
	public function tagdelAction(){
		$filter=new Zend_Filter_StripTags();
		$studenttag = new StudentTag();
		$student_id=$filter->filter(($this->_request->getParam('student_id')));
		$tag_id=$filter->filter(($this->_request->getParam('tag_id')));
		$query = $studenttag->delstudenttagBystudentid($student_id, $tag_id);
		if($query){
			echo "<script>window.location='tag?student_id=".$student_id."'</script>";
		}
	}

	public function tagAction(){
		$filter=new Zend_Filter_StripTags();
		$studenttag = new StudentTag();
		$student = new Student();
		$tag = new Tag();
		$student_id=$filter->filter(($this->_request->getParam('student_id')));
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$student_id=$filter->filter(($this->_request->getPost('student_id')));
			$tag_id=$_POST['tag_id'];
			
			$count = count($tag_id);
			if($count!=0){
				for($i=1;$i<=$count;$i++){
					$data=array(
					  'student_id'=>$student_id,
					  'tag_id'=>$tag_id[$i-1]
					);
					$studenttag->insert($data);
					unset($data);
				}
				echo "<script>window.location='detail?student_id=".$student_id."'</script>";
			}
		}else{
			$this->view->student = $student->getStudentBystudent_id($student_id);
			$tag_current = $studenttag->getstudenttagBystudent_id($student_id);
			$type=$filter->filter(($this->_request->getParam('type')));
			$search=$filter->filter(($this->_request->getParam('search')));
			$arr = array('0'=>'0');
			for($i=0;$i<count($tag_current);$i++){
				$arr[].=$tag_current[$i]['tag_id'];
			}
			$this->view->tag_current = $tag->getAllTagInArray($arr);
			if(!empty($type)){
				$this->view->tags = $tag->getAllTags('','','','');
			}else if(!empty($search)){
				$this->view->tags = $tag->getAllTags('','', $search,'');
			}else{
				$student = $this->view->student;
				$keys = $student[0]['key_word'];
				$this->view->tags = $tag->getAllTags('','','', $keys);
			}	
		}
		echo $this->view->render('student/tag.html');
	}
	
	public function editverifyidAction(){
		$filter=new Zend_Filter_StripTags();
		$studentclass = new StudentClass();
		$student = new Student();
		$student_id=$filter->filter(($this->_request->getParam('student_id')));
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$student_id=$filter->filter(($this->_request->getPost('student_id')));
			$class_id=$this->_request->getPost('class_id');
			$verify_id=$filter->filter(($this->_request->getPost('verify_id')));
			$data = array(
				'verify_id'=>$verify_id,
			);
			$studentclass->updateStudentClass($data, $student_id, $class_id);
			echo "<script>window.history.go(-1);</script>";
		}
	}
	
	public function typestatAction(){
		$filter=new Zend_Filter_StripTags();
		$year=$filter->filter(($this->_request->getParam('year')));
		$category=$filter->filter(($this->_request->getParam('category')));
		$page=$filter->filter(($this->_request->getParam('page')));
		$page = !empty($page)?$page:1;
		$project = new Project();
		$student = new Student();
		$company = new Company();
		$studenttag = new StudentTag();
		$tag = new Tag();
		$time1 = strtotime($year.'-01-01');
		$time2 = strtotime(($year+1).'-01-01');
		$arrProject = $project->getProjectByTimeType($time1,$time2,$category);
		foreach($arrProject as $row){
			$arrStudentId[] = $row['student_id'];
		}
		$arrStudent = $student->getAllstudentInArray($arrStudentId);
		$total = count($arrStudent);
		$perpage = 10;
		$arrStudent = array_slice($arrStudent,($page-1)*$perpage,$perpage);
		foreach($arrStudent as $key=>$row){
			$arrCompany = $company->getCompanyBycompany_id($row['company_id']);
			$arrTag = $studenttag->getstudenttagBystudent_id($row['student_id']);
			foreach($arrTag as $tag_key=>$tag_row){
				$arrTagInfo = $tag->gettagBytag_id($tag_row['tag_id']);
				$arrTagName[] = $arrTagInfo[0]['name'];
			}
			$arrStudent[$key]['company_name'] = $arrCompany[0]['name'];
			if (!empty($arrTagName)) {
				$arrStudent[$key]['tag_name'] = implode('，', $arrTagName);
			}
		}
		$this->view->arrStudent = $arrStudent;
		
		$pages = ceil($total/$perpage);
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;
		
		echo $this->view->render('student/typestat.html');
	}
	
	public function barAction(){
		srand((double)microtime()*1000000);
		$data = array();
		
		// add random height bars:
		for( $i=0; $i<20; $i++ ){
			$data[] = rand(2,100);
		}
		
		require_once('./public/chart/gallery/OFC/OFC_Chart.php');
		
		$title = new OFC_Elements_Title( date("D M d Y") );
		
		$bar = new OFC_Charts_Bar_3d();
		$bar->set_values( $data );
		$bar->colour = '#D54C78';
		
		$x_axis = new OFC_Elements_Axis_X();
		$x_axis->set_3d( 5 );
		$x_axis->colour = '#909090';
		$x_axis->set_labels( array(1,2,3,4,5,6,7,8,9,) );
		
		$y_axis = new OFC_Elements_Axis_Y();
		$y_axis->set_range( 0, 100, 10 );
			
		$chart = new OFC_Chart();
		$chart->set_title( $title );
		$chart->add_element( $bar );
		$chart->set_x_axis( $x_axis );
		$chart->set_y_axis( $y_axis );
		
		echo $chart->toPrettyString();
	}
	
	public function barsAction(){
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		
		$title = new title( date("学生分布") );
		
		$arr1 = $arrTypeNum[0];
		$arr2 = $arrTypeNum[1];
		$arr3 = $arrTypeNum[2];
		$arr4 = $arrTypeNum[3];
		$arrMax = array(max($arr1),max($arr2),max($arr3),max($arr4));
		$intMax = max($arrMax);
		$y_num = ($intMax>=10)?ceil($intMax/10)*10:10;
		
		$bar1 = new bar_glass();
		$bar1->set_values( $arr1 );
		$bar1->set_colour('#006600');
		$bar1->set_on_show(new bar_on_show('pop-up',0.5,0.2));
		$bar1->set_tooltip( 'GB：#val#' );
		
		$bar2 = new bar_glass();
		$bar2->set_values( $arr2 );
		$bar2->set_colour('#000000');
		$bar2->set_on_show(new bar_on_show('pop-up',0.5,0.2));
		$bar2->set_tooltip( 'BB：#val#' );
		
		$bar3 = new bar_glass();
		$bar3->set_values( $arr3 );
		$bar3->set_colour('#0000ff');
		$bar3->set_on_show(new bar_on_show('pop-up',0.5,0.2));
		$bar3->set_tooltip( 'CH：#val#' );
		
		$bar4 = new bar_glass();
		$bar4->set_values( $arr4 );
		$bar4->set_colour('#ff00ff');
		$bar4->set_on_show(new bar_on_show('pop-up',0.5,0.2));
		$bar4->set_tooltip( 'TT：#val#' );
		
		$y = new y_axis(); 
		$y->set_range( 0, $y_num, $y_num/10 );
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( $title );
		$chart->add_element( $bar1 );
		$chart->add_element( $bar2 );
		$chart->add_element( $bar3 );
		$chart->add_element( $bar4 );
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );
		
		echo $chart->toPrettyString();
	}
	
	public function lineAction(){
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		$filter=new Zend_Filter_StripTags();
		$project_type = $this->view->conf ->projectType;
		$type = array();
	    foreach($project_type as $s=>$l){
	    	$type[] = $l;
	    }
		$key_id=$filter->filter(($this->_request->getParam('key')));
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		
		include './public/chart/php-ofc-library/open-flash-chart.php';

		$arr1 = $arrTypeNum[$key_id];
		
		$intMax = max($arr1);
		$y_num = ($intMax>=10)?ceil($intMax/10)*10:10;
		
		$data_1 = $arr1;
		
		$default_dot = new dot();
		$default_dot->size(5)->colour(rand_color());
		
		$line_dot = new line();
		$line_dot->set_default_dot_style($default_dot);
		$line_dot->set_width( 4 );
		$line_dot->set_colour(rand_color());
		$line_dot->set_values( $data_1 );
		$line_dot->set_key( $type[$key_id], 10 );
		
		$y = new y_axis();
		$y->set_range( 0, $y_num, $y_num/10 ); 
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( new title( $type[$key_id].' student' ) );
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );

		$chart->add_element( $line_dot );
		
		echo $chart->toPrettyString();
	}
	
	
	public function pie1Action(){
		$filter = new Zend_Filter_StripTags();
		$project = new Project();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<1;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrProjectType[] = array(0,0,0,0);
		}
		//$arrYear = array_reverse($arrYear);
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrProject = array();
		foreach($arrTime as $key=>$row){
			$arrProject = $project->getProjectByTime($row[0] ,$row[1]);
			foreach($arrProject as $k=>$v){
				$arrProjectType[$key][$arrProject[$k]['category']]++;
			}
		}
		$count = count($arrProjectType);
		for($i=0;$i<$count;$i++){
			foreach($arrProjectType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		
		$d = array();
		$d[] = new pie_value($arrTypeNum[0][0], "GB");
		$d[] = new pie_value($arrTypeNum[1][0], "BB");
		$d[] = new pie_value($arrTypeNum[2][0], "CH");
		$d[] = new pie_value($arrTypeNum[3][0], "TT");

		
		$pie = new pie();
		$pie->alpha(0.5);
    	$pie->add_animation( new pie_fade() );
    	$pie->add_animation( new pie_bounce(4) );
		$pie->set_animate( true );
		$pie->set_label_colour( '#432BAF' );
		$pie->set_alpha( 0.75 );
		$pie->set_tooltip( '#label#<br>#val# (#percent#)' );
		$pie->set_colours(
			array(
            '#339900',
            '#660066',
            '#1F8FA1',
            '#ff0033'
        ) );
		
		$pie->set_values( $d );
		$title = new title( $year.'年学生数量分布' );
		$chart = new open_flash_chart();
		$chart->set_title( $title );
		$chart->add_element( $pie );
		
		echo $chart->toPrettyString();
	}
	
	public function pie2Action(){
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		$d = array();
		$d[] = new pie_value(120, "X");
		$d[] = new pie_value(99, "Y");
		
		$slice = new pie_value(21, "Z");
		$d[] = $slice;
		
		$pie = new pie();
		$pie->set_animate( true );
		$pie->set_label_colour( '#432BAF' );
		$pie->set_alpha( 0.75 );
		$pie->set_tooltip( '#label#<br>$#val# (#percent#)' );
		$pie->set_colours(
			array(
				'#77CC6D',    // income (green)
				'#FF5973',    // spend (pink)
				'#6D86CC'    // profit (blue)
			) );
		
		$pie->set_values( $d );
		
		$chart = new open_flash_chart();
		$chart->add_element( $pie );
		
		echo $chart->toPrettyString();
	}
}
?>